package cn.edu.uestc.topo;

import org.json.JSONObject;

public class SegmentRoutingCapability {

    private boolean isSrCapable = true;
    private long minLbl = 16;
    private long maxLbl = 1048575;
    private int lblStackDepth = 16;

    public SegmentRoutingCapability() {

    }

    public boolean isSrCapable() {
        return isSrCapable;
    }

    public void setSrCapable(boolean isSrCapable) {
        this.isSrCapable = isSrCapable;
    }

    public long getMinLbl() {
        return minLbl;
    }

    public void setMinLbl(long minLbl) {
        this.minLbl = minLbl;
    }

    public long getMaxLbl() {
        return maxLbl;
    }

    public void setMaxLbl(long maxLbl) {
        this.maxLbl = maxLbl;
    }

    public int getLblStackDepth() {
        return lblStackDepth;
    }

    public void setLblStackDepth(int lblStackDepth) {
        this.lblStackDepth = lblStackDepth;
    }

    public void readFromJson(JSONObject jsonObject) {
        try {
            this.isSrCapable = jsonObject.getBoolean("isSrCapable");
            this.minLbl = jsonObject.getLong("minLabel");
            this.maxLbl = jsonObject.getLong("maxLabel");
            this.lblStackDepth = jsonObject.getInt("labelStackDepth");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public JSONObject writeToJson() {
        JSONObject jsonObject = new JSONObject();
        try {
            jsonObject.put("isSrCapable", isSrCapable);
            jsonObject.put("minLabel", minLbl);
            jsonObject.put("maxLabel", maxLbl);
            jsonObject.put("labelStackDepth", lblStackDepth);
        } catch (Exception e) {
            e.printStackTrace();
        }

        return jsonObject;
    }

    @Override
    public String toString() {
        String stringContent = null;
        try {
            stringContent = this.writeToJson().toString();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return stringContent;
    }
}
